package com.myhome.money.jetty;

import ch.qos.logback.classic.Level;
import ch.qos.logback.classic.LoggerContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author 许路路
 */
@RestController
@SpringBootApplication
public class JettyDemoBootstrap {

    private static Logger logger = LoggerFactory.getLogger(JettyDemoBootstrap.class);

    public static void main(String[] args) {
        SpringApplication.run(JettyDemoBootstrap.class, args);
    }

    @GetMapping(value = "logLevel")
    public String changeLogLevel(String packageName, String logLevel) {
        try {
            LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
            loggerContext.getLogger(packageName).setLevel(Level.valueOf(logLevel));
        } catch (Exception e) {
            logger.error("动态修改日志级别出错", e);
            return "fail";
        }
        return "success";
    }

    @GetMapping("home")
    public String home() {
        logger.debug("0000debug....");
        logger.info("0000info....");
        logger.warn("0000warn....");
        logger.error("0000error...");
        return "home";
    }

}
